home *** CD-ROM | disk | FTP | other *** search
/ Space & Astronomy / Space and Astronomy (October 1993).iso / mac / VIEWERS / AMIGA / GIF2IFF.ZOO / convert.doc < prev    next >
Text File  |  1989-04-26  |  5KB  |  132 lines

  1.      
  2.      
  3.      I was exploring BBS's one day and  came across one for IBM's that
  4.      had several digitized images in GIF  format. Out of curiousity, I
  5.      downloaded a couple and  tried  to  display  them  using 'giffy'.
  6.      Nothing coherent. Still curious I put together a quick program to
  7.      decode GIF(which  uses  a  form  LZW  compression-interesting  in
  8.      itself) and saved the pictures  in  a more simpler format. When I
  9.      make reference to TMP files in  this  doc,  I'm referring to this
  10.      format, which is as follows:
  11.      
  12.      
  13.      struct TMPFILE
  14.      {
  15.       SHORT ImageWidth,ImageHeight,NoOfColorRegisters;
  16.       Struct COLORREGISTER ColorRegisters[NoOfColorRegisters];
  17.       UBYTE Image[ImageHeight][ImageWidth];
  18.      }
  19.      
  20.      where struct COLORREGISTER is
  21.      
  22.      struct COLORREGISTER
  23.      {
  24.       UBYTE red;
  25.       UBYTE green;
  26.       UBYTE blue;
  27.      }
  28.      ** Note that the picture is Image[y][x] not Image[x][y] **
  29.      
  30.      
  31.      The Image array indexes into the ColorRegisters array, which hold
  32.      the actual color values. For example-The red component of a pixel
  33.      (x,y) is given by the value of   ColorRegisters[Image[y][x]].red.
  34.      A value of 255 is all the  way  on.  A  value of 0 is all the way
  35.      off. Since the Amiga can only display  4 bits per color component
  36.      the following equation should be used:
  37.      
  38.        temp=ColorRegisters[Image[y][x]].red
  39.        RedComponent = (tmp>>4)&0x0f; 
  40.      
  41.      And'ing the value with 0x0f  probably  isn't  necessary but helps
  42.      conceptually.
  43.      
  44.      
  45.      If the Image  is  Interlaced,  GIFtoTMP  will  use  exit(5)  upon
  46.      completion in addition to a  written  message. This allows you to
  47.      check for this condition  in  a  CLI  script  file.  See the file
  48.      'convert' for an example.  The  file  Unlace  can then be used to
  49.      un-interlace the image. 
  50.      
  51.      
  52.      The last program, TMPtoIFF,  is  the  heart  of this series. When
  53.      converting the TMP file  into  an  Amiga  IFF file, the number of
  54.      color registers must  be  reduced  (usually  from  256). TMPtoIFF
  55.      currently offers three algorithms to do this:
  56.      
  57.        Popularity-Merely chooses the top most used colors
  58.      
  59.        Median Cut-Thinks of the colors as points in three dimensional
  60.                   space (Red,Green+Blue) and draws a box that
  61.                   encloses all points. The program then divides that
  62.                   box into two boxes with an equal number of colors in
  63.                   each side. (A pure white screen would only have one
  64.                   color-even though it is used in thousands of pixels)
  65.                   The boxes are continuously divided along their
  66.                   longest axis until there are as many boxes as the
  67.                   number of colors that you want. Then the colors in
  68.                   each box are averaged and those values are used in
  69.                   the final color map.
  70.      
  71.        Weighted Median Cut-I modified the above algorithm so that as
  72.                   it's dividing each box along its longest axis, it
  73.                   tries to put an equal number of pixels in each side
  74.                   (which of course is impossible to do exactly)
  75.                   This produces averaged colors closer to the majority
  76.                   colors, but also provides the variety that the 
  77.                   Median Cut does
  78.      
  79.      After one of  the  above  algorithms  is  run,  each pixel in the
  80.      original image is replaced with  the  closest  value in the final
  81.      color map. If a HAM image is  requested,  the program uses one of
  82.      the above algorithms to produce  the  color register values. This
  83.      works very well in practice.
  84.      
  85.      
  86.      Summary of Files:
  87.      
  88.         GIFtoTMP    Converts GIF files into TMP files
  89.      
  90.         Unlace      Will unlace a TMP file. Use only if
  91.                     GIFtoTMP indicates it as such
  92.      
  93.         TMPtoIFF    Converts TMP files into IFF files
  94.      
  95.         convert     the CLI file I use to convert the images
  96.                     usage as such: 
  97.      
  98.                 convert giffilepath giffilename [options for TMPtoIFF]
  99.      
  100.      
  101.      The usage of each file (except  convert)  can  be found be typing
  102.      the name of each file and pressing return.
  103.      
  104.      I've only tried this progam on 320x200 and 320x240 images. If you
  105.      try larger  images,  like  640x400  make  sure  you have a lot of
  106.      memory. Although I wrote this program specifically for converting 
  107.      IBM GIF images to Amiga  IFF  images,  it  will hopefully work on
  108.      most GIF files. Let me know if you  have any problems. One that I
  109.      already know of  is  if  you  specify  a  final  image  of  5 bit
  110.      planes(32 colors) and  the  original  GIF  image has less than 32
  111.      colors.
  112.      
  113.      
  114.                                   Mark Podlipec
  115.                                   111-4 BroadMeadow Rd
  116.                                   Marlboro MA  01752
  117.      
  118.      
  119.                                   
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.